package jMiiEditor.mii.checker;

/**
 * @author CC
 *
 */
public class MiiCheckerProposalRenameAction
    extends MiiCheckerProposalAbstractAction
        //implements MiiCheckerProposalAction
{
    private static final long serialVersionUID = 1L;
//    private String message;
    /** @serial */
    private String renameTo;

    public MiiCheckerProposalRenameAction(
            String message,
            String renameTo
            )
    {
        super(message,true);

        this.renameTo = renameTo.trim();

        if( !this.renameTo.endsWith( ".mii" ) ) {
            if( !this.renameTo.endsWith( ".mae" ) ) {
                this.renameTo = this.renameTo + ".mii";
            }
        }
    }

//    @Override
//    public String getMessage()
//    {
//        return message;
//    }

    @Override
    public String getMessageAction()
    {
        return "rename file to " + renameTo;
    }

    /**
     * Provided for remote file systems
     * @return the renameTo
     */
    public String getRenameTo()
    {
        return renameTo;
    }

    @Override
    public String getParameterString()
    {
        return renameTo;
    }

    @Override
    public boolean setParameterString( String newValue )
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void applyOn( MiiCheckerResult aMiiCheckerResult )
            throws MiiCheckerActionException
    {
        MiiCheckerFileObject newFO = applyOn( aMiiCheckerResult.getMiiCheckerFileObject() );

        aMiiCheckerResult.setMiiCheckerFileObject( newFO );
        aMiiCheckerResult.addAction( getMessageAction() );
    }

    private MiiCheckerFileObject applyOn( MiiCheckerFileObject aMiiCheckerFileObject )
        throws MiiCheckerActionException
    {
        return aMiiCheckerFileObject.renameTo( renameTo );
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append( "MiiCheckerResultFileAction [getMessage()=" );
        builder.append( getMessage() );
        builder.append( ", getMessageAction()=" );
        builder.append( getMessageAction() );
        builder.append( "]" );
        return builder.toString();
    }

}
